package com.ld.admin.controller.oa.work;

import java.util.Date;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ld.admin.controller.AdminBasicController;
import com.ld.admin.model.oa.work.WeeklyReportModel;
import com.ld.admin.service.oa.work.TodayTaskService;
import com.ld.admin.service.oa.work.WeeklyReportService;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.web.util.Web;
import com.ld.shieldsb.dao.model.QueryModel;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * 工作周报
 * 
 * @ClassName WeeklyReportController
 * @author <a href="mailto:1769975326@qq.com" target="_blank">黄升军</a>
 * @date 2019年08月15日 17:22:54
 *
 */
@Api(tags = "工作周报")
@Controller(value = "")
@RequestMapping("${shieldsb.adminPath}/oa/work/weeklyReport")
public class WeeklyReportController extends AdminBasicController<WeeklyReportModel> {
	@Autowired
	protected WeeklyReportService weeklyReportService;
	@Autowired
	protected TodayTaskService todayTaskService;

	@ApiOperation(value = "首页", notes = "")
	@RequestMapping(path = "", method = RequestMethod.GET)
	public String index() {
		todayTaskService.permission();
		return "a/oa/work/weeklyreport/weeklyreport_header";
	}

	@ApiOperation(value = "到搜索页面", notes = "")
	@RequestMapping(path = "/toSearch", method = RequestMethod.GET)
	public String toSearch(HttpSession session, String sign) {
		session.setAttribute("weekSign", sign);// 存入自己下级全部的页签标识
		todayTaskService.getUserListBySign(sign);
		Date now = new Date();
		weeklyReportService.getTimeInterval(now);
		return "a/oa/work/weeklyreport/weeklyreport_search";
	}

	@ApiOperation(value = "搜索结果", notes = "")
	@RequestMapping(path = "/search", method = RequestMethod.POST)
	public String search(HttpSession session, String week) {

		String sign = (String) session.getAttribute("weekSign");
		QueryModel queryModel = weeklyReportService.getSearchQueryModel(request);
		todayTaskService.getTaskBySign(sign, queryModel);
		weeklyReportService.getPageBean(request, getModelClass(), queryModel);
		return "a/oa/work/weeklyreport/weeklyreport_list";
	}

	@ApiOperation(value = "工作周报展示", notes = "")
	@RequestMapping(path = "/show", method = RequestMethod.GET)
	public String show(String week) {
		long id = getLong("id");
		weeklyReportService.getOne(request, getModelClass(), id);
		return "a/oa/work/weeklyreport/weeklyreport_show";
	}

	@ApiOperation(value = "跳转到添加/修改工作周报", notes = "")
	@RequestMapping(path = "/toAddOrUpdate", method = RequestMethod.GET)
	public String toAddOrUpd(String week) {
		long id = getLong("id");
		todayTaskService.getUserList();
		Date now = new Date();
		weeklyReportService.getTimeInterval(now);
		weeklyReportService.getOne(request, getModelClass(), id);
		return "a/oa/work/weeklyreport/weeklyreport_update";
	}

	@ApiOperation(value = "添加/修改工作周报", notes = "")
	@RequestMapping(path = "/addOrUpdate", method = RequestMethod.POST)
	// 返回json格式
	@ResponseBody
	public Object addOrUpd(@Valid WeeklyReportModel model) {
		return weeklyReportService.addOrUpdate(model);
	}

	@ApiOperation(value = "删除工作周报", notes = "")
	@RequestMapping(path = "/del", method = RequestMethod.POST)
	// 返回json格式
	@ResponseBody
	public Object del() {
		long id = getLong("id");
		Result result = weeklyReportService.remove(getModelClass(), id);
		return Web.Response.result(result);
	}

}